package cz.uhk.domain;

import java.util.Random;

import javax.swing.JTextArea;

public class Mys {
	
	Mistnost mistnost;
	Bludiste bludiste;
	JTextArea text;
	
	
	
	public Mys(Bludiste bludiste) {
		super();
		this.bludiste = bludiste;
		najdiZacatek();
	}

	public int hledejSyr(){
		
		String s="";
		int count = 0;
		while(!mistnost.isSyr()){
			s="";
			int iDvere = random(0,mistnost.getDvere().size()-1);
			s = s +(mistnost.getCislo()-4);
			mistnost = mistnost.getDvere().get(iDvere).getOpacnouMistnost(mistnost);
			s =s + "=>"+(mistnost.getCislo()-4)+";";
			text.setText(text.getText()+s);
			count++;
		}
		text.setText(text.getText()+"\n");
		text.setText(text.getText()+"================================\n");
		text.select(text.getDocument().getLength(),text.getDocument().getLength() );
		return count;
	}
	
	public int random(int a, int b){
		int random = 0;
		random = a + new Random().nextInt(b-a+1);
		return random;
	}
	
	public void najdiZacatek(){
		for (Mistnost m : bludiste.getMistnosti()) {
			if(m.isMouse()) this.mistnost = m;
		}
	}

	public JTextArea getText() {
		return text;
	}

	public void setText(JTextArea text) {
		this.text = text;
	}
	
	

}
